<!-- html -->
<template>
  <h2 class="h2">readonly，只读</h2>
  <span class="span3">ref</span>
  <br>
  <span class="span2">num1：{{ num1 }}</span>
  <button class="button1" @click="changeNum1">修改num1</button>
  <hr class="hr1">
  <span class="span3">readonly</span>
  <br>
  <span class="span2">num2：{{ num2 }}</span>
  <button class="button1" @click="changeNum2">修改num2</button>
</template>

<!-- js或ts -->
<script lang="ts">
export default {
  name: 'readonlyTest1'
}
</script>

<!-- js或ts -->
<script setup lang="ts">
import { ref, readonly } from 'vue'
//数据
let num1 = ref(1)
//只读
let num2 = readonly(num1)
//方法
function changeNum1() {
  num1.value += 1
}
function changeNum2() {
  num2.value += 1
}
</script>

<!-- 样式 -->
<style scoped></style>